package com.bw.gmallController;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.gmallService.GmallService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author: Shi san
 * @Date: 2025/7/15 09:26
 * @Description:
 **/
@RestController
public class GmallController {
    @Autowired
    GmallService gmallService;

    @RequestMapping("/zhutotal")
    public Object zhutotal(){
        List<Map> list = gmallService.zhutotal();
        JSONObject object = new JSONObject();
        object.put("status",0);
        object.put("msg","");

        JSONObject data = new JSONObject();
        JSONArray categories = new JSONArray();
        for (Map map : list) {
            categories.add(map.get("name"));
        }

        JSONObject object1 = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        JSONArray xjsonArray = new JSONArray();
        for (Map map : list) {
            xjsonArray.add(map.get("sum"));
        }
        jsonArray.add(object1);
        object1.put("data",xjsonArray);
        data.put("categories",categories);
        data.put("series",jsonArray);
        object.put("data",data);
        return object;
    }

    @RequestMapping("/luntotal")
    public Object luntotal(){
        List<Map> list = gmallService.luntotal();
        JSONObject object = new JSONObject();
        object.put("status",0);
        object.put("msg","");

        JSONObject data = new JSONObject();
        JSONArray jsonArray = new JSONArray();

        JSONObject object1 = new JSONObject();
        object1.put("name","品牌");
        object1.put("id","pname");
        jsonArray.add(object1);

        JSONObject object2 = new JSONObject();
        object2.put("name","性别");
        object2.put("id","sex");
        jsonArray.add(object2);

        JSONObject object3 = new JSONObject();
        object3.put("name","总金额");
        object3.put("id","sum");
        jsonArray.add(object3);

        JSONArray jsonArray1 = new JSONArray();
        for (Map map : list) {
            JSONObject rows = new JSONObject();
            rows.put("pname",map.get("pname"));
            if (map.get("sex")=="F"){
                System.out.println("男");
            }
            rows.put("sex",map.get("sex"));
            rows.put("sum",map.get("sum"));
            jsonArray1.add(rows);
        }
        data.put("columns",jsonArray);
        data.put("rows",jsonArray1);
        object.put("data",data);
        return object;
    }

    @RequestMapping("/bingtotal1")
    public Object bingtotal1(){
        List<Map> list = gmallService.bingtotal1();
        JSONObject object = new JSONObject();
        object.put("status",0);
        object.put("msg","");

        JSONArray dataArray = new JSONArray();
        for (Map map : list) {
            JSONObject object1 = new JSONObject();
            object1.put("name",map.get("year"));
            object1.put("value",map.get("bili"));
            dataArray.add(object1);
        }
        object.put("data",dataArray);
        return object;
    }

    @RequestMapping("/bingtotal2")
    public Object bingtotal2(){
        List<Map> list = gmallService.bingtotal2();
        JSONObject object = new JSONObject();
        object.put("status",0);
        object.put("msg","");

        JSONArray dataArray = new JSONArray();
        for (Map map : list) {
            JSONObject object1 = new JSONObject();
            object1.put("name",map.get("name"));
            object1.put("value",map.get("bili"));
            dataArray.add(object1);
        }
        object.put("data",dataArray);
        return object;
    }
}
